---@class DarkStreetPlayerData
local PlayerData = Class("PlayerData")
function PlayerData:ctor()
    self.resNum = 0
    self.buff = 0
    self.resNumChange = 0
    self.bagChangeData = nil
    self.winStreakCount = 0
end

---@class RedRob.GameMode
local GameMode = RedRob.CreateSingleton("GameMode")
local this = GameMode
function GameMode.OnCreate()
    this.bagList = {}
    ---@type DarkStreetPlayerData[]
    this.playerResourceList = {}
    this.resRefreshTipList = {}
    this.midTipList = {}
end
function GameMode.OnDestroy()
    this.bagList = nil
    this.playerResourceList = nil
    this.resRefreshTipList = nil
    this.midTipList = nil
end
function GameMode.GetBagList()
    return this.bagList
end
---@param itemList TempItemBean[]
function GameMode.InitBagList(itemList)
    table.clear(this.bagList)
    for k,v in pairs(itemList) do
       this.bagList[v.itemModelId] = {itemModelId = v.itemModelId,num = v.num,change = 0}
    end
end
---@param item TempItemBean
function GameMode.AddBag(item)
    if item.num > 0 then
        local data = this.bagList[item.itemModelId]
        if not data then
            data = {itemModelId = item.itemModelId,num = item.num,change = item.num}
            this.bagList[item.itemModelId] = data
            this.bagChangeData = data
        else
            data.change = item.num - data.num
            data.num = item.num
            this.bagChangeData = data
        end
    else
        this.bagList[item.itemModelId] = nil
    end
end
function GameMode.GetBagChangeData()
    return this.bagChangeData
end
function GameMode.GetOrCreatePlayerData(playerId)
    local data = this.playerResourceList[playerId]
    if not data then
        data = PlayerData.New()
        this.playerResourceList[playerId] = data
        data.resNum = 0
    end
    return data
end
function GameMode.SetWinStreakCount(playerId,count)
    local data = this.GetOrCreatePlayerData(playerId)
    data.winStreakCount = count
end
function GameMode.PlayerResourceUpdate(playerId,curNum)
    local data = this.GetOrCreatePlayerData(playerId)
    data.resNum = curNum
end
function GameMode.PlayerResourceChange(playerId,changeNum)
    local data = this.GetOrCreatePlayerData(playerId)
    data.resNumChange = changeNum
end
function GameMode.SetAttrReduce(playerId,attrReduce)
    local data = this.GetOrCreatePlayerData(playerId)
    data.buff = -math.abs(attrReduce/100)
end
---@return DarkStreetPlayerData
function GameMode.GetPlayerData(playerId)
    return this.playerResourceList[playerId]
end
function GameMode.GetMyRes()
    local data = this.playerResourceList[RedRob.KeyController.GetCtrl():GetId()]
    return data
end
function GameMode.UpdateResRefreshTip(eventId,_type,mineralIdList,delay,isSpecialStone)
    this.RemoveOverTimeResTip()
    local cur = RedRob.ClientBattle.GetBattleTime()
    if _type == 1 then
        local list
        if mineralIdList then
            list = {}
            for k,v in pairs(mineralIdList) do
                table.insert(list,v)
            end
        end
        table.insert(this.resRefreshTipList,{eventId = eventId,idList = list,
                                             endTime = delay + cur,dieTime = delay + cur + 2,isSpecialStone = isSpecialStone})
    end
end
function GameMode.RemoveOverTimeResTip()
    local cur = RedRob.ClientBattle.GetBattleTime()
    local removed = TablePool.Get()
    for k,v in pairs(this.resRefreshTipList) do
        if v.dieTime > 0 and cur >= v.dieTime then
            table.insert(removed,v)
        end
    end
    for k,v in pairs(removed) do
        table.ArrayRemoveByValue(this.resRefreshTipList,v)
    end
    TablePool.ReleaseDeeper(removed,false)
end
function GameMode.AddMidTip(modelId,isKill,killPlayerId)
    local cfg = dataTable.getDataTableByStringId("t_darkstreetstone",modelId)
    if cfg then
        for k,v in pairs(this.midTipList) do
            if v._type == cfg.f_type and v.isKill == isKill then
                return
            end
        end
    end
    table.insert(this.midTipList,{modelId = modelId,_type = cfg.f_type, isKill = isKill,killPlayerId = killPlayerId})
    FireEvent(RedRob.Config.Event.MidRefreshTip)
end
function GameMode.GetMidTip()
    if #this.midTipList > 0 then
        return table.remove(this.midTipList,1)
    end
    return nil
end
